package models

import (
	"goim-pro/internal/app/repos/base"
	tbl "goim-pro/internal/db"
	"time"
)

// 推送发起渠道
const (
	ChannelOfSystem Channel = "SYSTEM"
	ChannelOfUser   Channel = "USER"
	ChannelOfOthers Channel = "OTHERS"
)

// 内容模块分类
const (
	ClassOfUnknown          Classify = 0 //未知的，默认值类型
	ClassOfChatPrivate      Classify = 1 //私聊信息
	ClassOfChatGroup        Classify = 2 //群组信息
	ClassOfContactOperation Classify = 3 //联系人操作信息
)

// 推送消息状态
const (
	NtfStatusOfPending  NotificationStatus = "PENDING"
	NtfStatusOfSent     NotificationStatus = "SENT"
	NtfStatusOfReceived NotificationStatus = "RECEIVED"
	NtfStatusOfRead     NotificationStatus = "READ"
	NtfStatusOfCancel   NotificationStatus = "CANCEL"
)

// 推送内容类型
const (
	ObjectNameTxtMsg        ObjectName = "GM:TxtMsg"         // text
	ObjectNameImgMsg        ObjectName = "GM:ImgMsg"         // IMG
	ObjectNameGIFMsg        ObjectName = "GM:GIFMsg"         // GIF
	ObjectNameHQVCMsg       ObjectName = "GM:HQVCMsg"        // 语音消息
	ObjectNameFileMsg       ObjectName = "GM:FileMsg"        // 文件消息
	ObjectNameSightMsg      ObjectName = "GM:SightMsg"       // 小视频消息
	ObjectNameLBSMsg        ObjectName = "GM:LBSMsg"         // 位置消息
	ObjectNameInfoNtf       ObjectName = "GM:InfoNtf"        // 小灰条提示消息，e.g：请在聊天中注意人身财产安全
	ObjectNameProfileNtf    ObjectName = "GM:ProfileNtf"     // 资料变更通知消息
	ObjectNameContactNtf    ObjectName = "GM:ContactNtf"     // 联系人(好友)通知消息
	ObjectNameCmdMsg        ObjectName = "GM:CmdMsg"         // 命令消息
	ObjectNameCustomContact ObjectName = "Custom:ContactNtf" // 自定义：单用户通知
)

// 推送消息标识
const (
	MsgFlagContactRequest NtfMessageFlag = "CT_REQ"
	MsgFlagContactAccept  NtfMessageFlag = "CT_ACT"
	MsgFlagContactRefuse  NtfMessageFlag = "CT_REF"
	MsgFlagContactDelete  NtfMessageFlag = "CT_DEL"
)

type Channel string
type Classify int
type NotificationStatus string
type ObjectName string
type NtfMessageFlag string

type Notification struct {
	NtfId        string             `json:"ntfId" gorm:"column:ntfId; type:varchar(32); primary_key; not null"`
	PsId         string             `json:"messageId" gorm:"column:messageId; type:varchar(32); primary_key; not null"`
	SenderId     string             `json:"senderId" gorm:"column:senderId; type:varchar(32); not null"`                                       // 发起人
	RecipientId  string             `json:"recipientId" gorm:"column:recipientId; type:varchar(32); not null"`                                 // 接收人
	ObjectName   ObjectName         `json:"objectName" gorm:"column:objectName; type:varchar(50); not null"`                                   // 对象类型: 文本，图片，文件 etc..
	Content      string             `json:"content" gorm:"column:content; type:varchar(225); not null"`                                        // 推送消息内容
	PushContent  string             `json:"pushContent" gorm:"column:pushContent; type:varchar(225); not null"`                                // 定义显示的 Push 内容
	IsNeedRemind bool               `json:"remind" gorm:"column:remind; type:tinyint(1); default: 1; not null"`                                // 是否提示，默认 true
	MessageFlag  NtfMessageFlag     `json:"msgFlag" gorm:"column:msgFlag; type:varchar(20); not null"`                                         // 信息标识：针对不同推送内容模块可以有不同的信息标识，便于查询，e.g CT_REQ/CT_APT etc..
	NtfStatus    NotificationStatus `json:"ntfStatus" gorm:"column:ntfStatus; type:varchar(20); not null"`                                     // 推送状态
	Channel      Channel            `json:"channel" gorm:"column:channel; type:ENUM('SYSTEM', 'USER', 'OTHERS'); default: 'SYSTEM'; not null"` // 发起渠道
	DisablePush  bool               `json:"disablePush" gorm:"column:disablePush; type:tinyint(1); default: 0; not null"`                      // 禁止推送
	ReadAt       time.Time          `json:"readAt" gorm:"column:readAt;type:dateTime"`                                                         // 推送读取时间
	PushExt      PushExt            `gorm:"ForeignKey:psId"`                                                                                   // 推送内容、属性设置
	Sender       User               `gorm:"ForeignKey:senderId"`
	Recipient    User               `gorm:"ForeignKey:targetId"`
	base.BaseModel
}

type PushExt struct {
	PsId       string   `json:"psId" gorm:"column:psId;type:varchar(32);primary_key;not null"`
	Title      string   `json:"title" gorm:"column:title;type:varchar(100);not null"`
	Classify   Classify `json:"classify" gorm:"column:classify;type:tinyint(1);default:0;not null"` // 内容模块分类，默认 0(UNKNOWN)
	TemplateId string   `json:"templateId" gorm:"column:templateId;type:int(32);not null"`          // TODO:预留字段：推送模板 ID
	ChannelId  string   `json:"channelId" gorm:"column:channelId;type:int(32);not null"`            // TODO:预留字段：渠道ID，"HW", "XM", "OPPP" etc.
	Extra      string   `json:"extra" gorm:"column:extra;type:varchar(255);not null"`               // TODO:预留字段：拓展字段
	base.BaseModel
}

func (Notification) TableName() string {
	return tbl.TableNotifications
}

func (PushExt) TableName() string {
	return tbl.TableNotificationPushExts
}
